import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;



@XmlSeeAlso(B.class)
@XmlRootElement(name="a")
public class A {

	@XmlElement
	int x = 4;
	
	public static void main(String[] args) {
//		saveA();
//		loadA();
		
		loadB();
//		saveB();
	}

	protected static void saveB() {
		B a = new B();
		try {
			FileOutputStream outFileStream = new FileOutputStream("b");
			MarshelUtil.marshal(a, outFileStream);
			outFileStream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static void loadB() {
		InputStream inFileStream;
		try {
			inFileStream = new FileInputStream("a");
			B a = MarshelUtil.unmarshal(inFileStream , B.class);
			System.out.println(a);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public String toString() {
		return getClass() + "\nx = " + x;
	}
	
	protected static void loadA() {
		InputStream inFileStream;
		try {
			inFileStream = new FileInputStream("a");
			A a = MarshelUtil.unmarshal(inFileStream , A.class);
			System.out.println(a);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

	protected static void saveA() {
		A a = new A();
		try {
			FileOutputStream outFileStream = new FileOutputStream("a");
			MarshelUtil.marshal(a, outFileStream);
			outFileStream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
